package cn.itcast.multi.thread.lock;

/**
 * 乐观读 -- 悲观读 -- 互斥写
 * create by zhangtian3 on 2019/4/11
 */
public class StampedLockDemo {
    public static void main(String[] args) {
        final StampLockShareData stampLockShareData = new StampLockShareData();
        // 两个线程负责写读数据
        for (int i = 0; i < 20; i++) {
            new Thread() {
                @Override
                public void run() {
                    stampLockShareData.read();
                }
            }.start();
        }

        // 两个线程负责写数据
        for (int i = 0; i < 20; i++) {
            new Thread() {
                @Override
                public void run() {
                    stampLockShareData.write();
                }
            }.start();
        }
    }
}
